/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AutosVentana.java
 *
 * Created on 22/11/2010, 20:12:57
 */

package ar.com.educacionit.vehiculos.ventanas;

import ar.com.educacionit.vehiculos.entidades.Auto;
import ar.com.educacionit.vehiculos.util.MngrRecursos;
import java.sql.*;
import java.util.*;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;

/**
 *
 * @author matias
 */
public class AutosVentana extends javax.swing.JInternalFrame {
    public static boolean abierta;
    DefaultListModel modeloAutos = new DefaultListModel();

    private VentanaMaestra vm;
    public void limpiarCampos(){
        jTfAlt.setText("");
        jTfAncho.setText("");
        jTfLargo.setText("");
        jTfPrecio.setText("");
        jTextAreaEquip.setText("");
        jTfAlt.requestFocus();
        jCbColor.setSelectedIndex(0);
        jCbMarca.setSelectedIndex(0);
        jCbModelo.setSelectedIndex(0);
    }
    public void grabarDB(){
        boolean nuevo= true;
        JOptionPane.showMessageDialog(this,
                    "El Auto fue agregado con exito",
                    "Mensaje",
                    JOptionPane.INFORMATION_MESSAGE);
            
            Auto a= new Auto();
            if( jListAutos.getSelectedIndex() != -1 ){
                a = (Auto)jListAutos.getSelectedValue();
                nuevo = false;
            }

            a.setAlto(Integer.parseInt(jTfAlt.getText()));
            a.setAncho(Integer.parseInt(jTfAncho.getText()));
            a.setLargo(Integer.parseInt(jTfLargo.getText()));
            a.setPrecio(Double.parseDouble(jTfPrecio.getText()));
            a.setMarca((String) jCbMarca.getSelectedItem());
            a.setModelo((String) jCbModelo.getSelectedItem());
            a.setColor((String) jCbColor.getSelectedItem());
            a.setEquipamiento((jTextAreaEquip.getText()));

        try{
            if(nuevo){
                modeloAutos.addElement(a);                
                jListAutos.clearSelection();
                a.insertar(vm.getConnection());
               
            }else{
                a.modificar(vm.getConnection());
                modeloAutos.removeElement(jListAutos.getSelectedIndex());
                modeloAutos.addElement(a);
            }
            limpiarCampos();
            jButtonNuevo.setEnabled(true);
            jButtonGuardar.setEnabled(false);
        }catch(Exception e){
        
        }
    }
    public boolean validarCampos(){
        try{
                 int altura= Integer.parseInt(jTfAlt.getText());
            }catch(Exception e){
                 JOptionPane.showMessageDialog(this,
                    "La altura debe ser un numero entero",
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
                 jTfAlt.requestFocus();
                 return false;
             }
             try{
                 int ancho= Integer.parseInt(jTfAncho.getText());
             }catch(Exception e){
                 JOptionPane.showMessageDialog(this,
                    "El ancho debe ser un numero entero",
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
                 jTfAncho.requestFocus();
                 return false;
             }
            try{
                int largo= Integer.parseInt(jTfLargo.getText());
            }catch(Exception e){
                JOptionPane.showMessageDialog(this,
                    "El largo debe ser un numero entero",
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
                 jTfLargo.requestFocus();
                 return false;
            }
            try{
                double precio= Double.parseDouble(jTfPrecio.getText());
            }catch(Exception e){
                JOptionPane.showMessageDialog(this,
                    "El debe ser un numero con decimales",
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
                 jTfPrecio.requestFocus();
                 return false;
            }
        return true;
    }
    public boolean camposCompletos(){
        if(jTfAlt.getText().equals("")){
                JOptionPane.showMessageDialog(this,
                        "La altura no puede estar incompleta",
                        "Mensaje",
                        JOptionPane.WARNING_MESSAGE);
                jTfAlt.requestFocus();
                return false;
            }
            if(jTfAncho.getText().equals("")){
               JOptionPane.showMessageDialog(this,
                        "El ancho no puede estar incompleto",
                        "Mensaje",
                        JOptionPane.WARNING_MESSAGE);
                jTfAncho.requestFocus();
                return false;
            }
            if(jTfLargo.getText().equals("")){
                JOptionPane.showMessageDialog(this,
                        "El largo no puede estar incompleto",
                        "Mensaje",
                        JOptionPane.WARNING_MESSAGE);
                jTfLargo.requestFocus();
                return false;
            }
            if(jTfPrecio.getText().equals("")){
                JOptionPane.showMessageDialog(this,
                        "El precio no puede estar incompleto",
                        "Error",
                        JOptionPane.WARNING_MESSAGE);
                jTfPrecio.requestFocus();
                return false;
            }
            if(jTextAreaEquip.getText().equals("")){
                JOptionPane.showMessageDialog(this,
                        "El equipamiento no puede estar incompleto",
                        "Error",
                        JOptionPane.WARNING_MESSAGE);
                jTextAreaEquip.requestFocus();
                return false;
            }
            if(jCbColor.getSelectedIndex()==0){
            JOptionPane.showMessageDialog(this,
                        "Seleccione un color",
                        "Mensaje",
                        JOptionPane.WARNING_MESSAGE);
                jCbColor.requestFocus();
                return false;
            }
            if(jCbMarca.getSelectedIndex()==0){
            JOptionPane.showMessageDialog(this,
                        "Seleccione una marca",
                        "Mensaje",
                        JOptionPane.WARNING_MESSAGE);
                jCbMarca.requestFocus();
                return false;
            }
            if(jCbModelo.getSelectedIndex()==0){
            JOptionPane.showMessageDialog(this,
                        "Seleccione un modelo",
                        "Mensaje",
                        JOptionPane.WARNING_MESSAGE);
                jCbModelo.requestFocus();
                return false;
            }
        return true;
    }
    public void cargarCombos(){
        try{
            //Llena el combo color
            jCbColor.addItem("Seleccione...");
            List color= MngrRecursos.getColores();
            Iterator <String> itC= color.iterator();
            while(itC.hasNext()){
                String c= itC.next();
                jCbColor.addItem(c);
            }
            jCbColor.setSelectedIndex(0);
            
            //Llena el combo marca
            jCbMarca.addItem("Seleccione...");
            List marca= MngrRecursos.getMarca();
            Iterator <String> itM= marca.iterator();
            while(itM.hasNext()){
                String m= itM.next();
                jCbMarca.addItem(m);
            }
            jCbMarca.setSelectedIndex(0);

            //Llena el combo modelo
            jCbModelo.addItem("Seleccione...");
            for(Integer i=1985; i<=2010;++i){
                jCbModelo.addItem(i.toString());
            }
            jCbModelo.setSelectedIndex(0);
        }catch(Exception e){
            JOptionPane.showMessageDialog(
                    this,
                    "Los recursos no estan disponibles.\n        La aplicación se cerrara",
                    "Error",
                    JOptionPane.OK_OPTION);
            System.exit(0);
        }
    }
    public void cargarLista(){
        Auto a= new Auto();
        try{
            ArrayList aList= a.obtenerTodos(vm.getConnection());
            Iterator itA= aList.iterator();
            
            while(itA.hasNext()){
                Auto auto= (Auto) itA.next();
                modeloAutos.addElement(auto);
            }
        }catch(Exception e){
        }
    }

    public AutosVentana(VentanaMaestra vm){
        this.vm=vm;
        initComponents();
        cargarCombos();
        cargarLista();
        jListAutos.setModel(modeloAutos);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListAutos = new javax.swing.JList();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTfAlt = new javax.swing.JTextField();
        jTfAncho = new javax.swing.JTextField();
        jTfLargo = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jCbMarca = new javax.swing.JComboBox();
        jCbModelo = new javax.swing.JComboBox();
        jCbColor = new javax.swing.JComboBox();
        jTfPrecio = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextAreaEquip = new javax.swing.JTextArea();
        jSeparator1 = new javax.swing.JSeparator();
        jButtonCerrar = new javax.swing.JButton();
        jButtonEliminar = new javax.swing.JButton();
        jButtonGuardar = new javax.swing.JButton();
        jButtonNuevo = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Administración de Autos");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosed(evt);
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Listado de autos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12))); // NOI18N

        jListAutos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jListAutosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jListAutos);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dimensiones", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Ubuntu", 1, 13));
        jLabel1.setText("Altura");

        jLabel2.setFont(new java.awt.Font("Ubuntu", 1, 13));
        jLabel2.setText("Ancho");

        jLabel3.setFont(new java.awt.Font("Ubuntu", 1, 13));
        jLabel3.setText("Largo");

        jLabel4.setFont(new java.awt.Font("Ubuntu", 1, 13));
        jLabel4.setText("cm");

        jLabel5.setFont(new java.awt.Font("Ubuntu", 1, 13));
        jLabel5.setText("cm");

        jLabel6.setFont(new java.awt.Font("Ubuntu", 1, 13));
        jLabel6.setText("cm");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jTfAlt, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTfLargo, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jTfAncho, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel5))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addGap(14, 14, 14)
                                .addComponent(jLabel6)))))
                .addContainerGap(28, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTfAlt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTfAncho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTfLargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel7.setFont(new java.awt.Font("Ubuntu", 1, 13));
        jLabel7.setText("Marca");

        jLabel8.setFont(new java.awt.Font("Ubuntu", 1, 13));
        jLabel8.setText("Modelo");

        jLabel9.setFont(new java.awt.Font("Ubuntu", 1, 13));
        jLabel9.setText("Color");

        jLabel10.setFont(new java.awt.Font("Ubuntu", 1, 13));
        jLabel10.setText("Precio");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Caracteristicas/Equipamiento", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12))); // NOI18N

        jTextAreaEquip.setColumns(20);
        jTextAreaEquip.setRows(5);
        jScrollPane2.setViewportView(jTextAreaEquip);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 541, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE)
                .addContainerGap())
        );

        jButtonCerrar.setFont(new java.awt.Font("Ubuntu", 1, 13));
        jButtonCerrar.setText("Cerrar");
        jButtonCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCerrarActionPerformed(evt);
            }
        });

        jButtonEliminar.setFont(new java.awt.Font("Ubuntu", 1, 13));
        jButtonEliminar.setText("Eliminar");
        jButtonEliminar.setEnabled(false);
        jButtonEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEliminarActionPerformed(evt);
            }
        });

        jButtonGuardar.setFont(new java.awt.Font("Ubuntu", 1, 13));
        jButtonGuardar.setText("Guardar");
        jButtonGuardar.setEnabled(false);
        jButtonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarActionPerformed(evt);
            }
        });

        jButtonNuevo.setFont(new java.awt.Font("Ubuntu", 1, 13));
        jButtonNuevo.setText("Nuevo");
        jButtonNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonNuevoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(52, 52, 52)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addGap(21, 21, 21)
                                .addComponent(jCbModelo, 0, 201, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addGap(30, 30, 30)
                                .addComponent(jCbMarca, 0, 201, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel10))
                                .addGap(29, 29, 29)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTfPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jCbColor, 0, 201, Short.MAX_VALUE)))))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 577, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButtonNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 210, Short.MAX_VALUE)
                        .addComponent(jButtonCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jCbMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jCbModelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(jCbColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(jTfPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(26, 26, 26)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonNuevo)
                    .addComponent(jButtonGuardar)
                    .addComponent(jButtonEliminar)
                    .addComponent(jButtonCerrar))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formInternalFrameClosed(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosed
        abierta=false;
        vm.getjMenuAbirAutos().setEnabled(true);
    }//GEN-LAST:event_formInternalFrameClosed

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        abierta=true;
        vm.getjMenuAbirAutos().setEnabled(false);
    }//GEN-LAST:event_formInternalFrameOpened

    private void jButtonCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCerrarActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButtonCerrarActionPerformed

    private void jButtonNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNuevoActionPerformed
        limpiarCampos();
        jButtonNuevo.setEnabled(false);
        jButtonGuardar.setEnabled(true);
    }//GEN-LAST:event_jButtonNuevoActionPerformed

    private void jButtonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarActionPerformed
        if(jTfAlt.getText().equals("")|jTfAncho.getText().equals("")|jTfLargo.getText().equals("")|jTfPrecio.getText().equals("")|jTextAreaEquip.getText().equals("")|jCbColor.getSelectedIndex()==0|jCbMarca.getSelectedIndex()==0|jCbModelo.getSelectedIndex()==0){
            camposCompletos();
        }else{
            if (validarCampos()){
                grabarDB();
                limpiarCampos();
                //jListAutos.updateUI();
            }
        }
    }//GEN-LAST:event_jButtonGuardarActionPerformed

    private void jListAutosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jListAutosMouseClicked
        jButtonEliminar.setEnabled(true);
        jButtonGuardar.setEnabled(true);

        Auto a= (Auto) jListAutos.getSelectedValue();
        jTfAlt.setText(String.valueOf(a.getAlto()));
        jTfAncho.setText(String.valueOf(a.getAncho()));
        jTfLargo.setText(String.valueOf(a.getLargo()));
        jTfPrecio.setText(String.valueOf(a.getPrecio()));
        jTextAreaEquip.setText(String.valueOf(a.getEquipamiento()));

        jCbMarca.setSelectedItem(a.getMarca());
        jCbModelo.setSelectedItem(a.getModelo());
        jCbColor.setSelectedItem(a.getColor());


    }//GEN-LAST:event_jListAutosMouseClicked

    private void jButtonEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEliminarActionPerformed
        try {
            int rta = JOptionPane.showConfirmDialog(this, "¿Desea eliminar el auto " + jListAutos.getSelectedValue() + " ?", "Eliminar", JOptionPane.YES_NO_OPTION);
            // Si no desea borrarlo, entonces no lo borra
            if (rta == JOptionPane.NO_OPTION) {
                return;
            }
            Auto a = (Auto) jListAutos.getSelectedValue();
            modeloAutos.remove(jListAutos.getSelectedIndex());
            a.eliminar(vm.getConnection());
            jButtonGuardar.setEnabled(false);
            jButtonEliminar.setEnabled(false);
            jButtonNuevo.setEnabled(true);
            limpiarCampos();
        } catch (Exception ex) {
            
        }
    }//GEN-LAST:event_jButtonEliminarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCerrar;
    private javax.swing.JButton jButtonEliminar;
    private javax.swing.JButton jButtonGuardar;
    private javax.swing.JButton jButtonNuevo;
    private javax.swing.JComboBox jCbColor;
    private javax.swing.JComboBox jCbMarca;
    private javax.swing.JComboBox jCbModelo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jListAutos;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextArea jTextAreaEquip;
    private javax.swing.JTextField jTfAlt;
    private javax.swing.JTextField jTfAncho;
    private javax.swing.JTextField jTfLargo;
    private javax.swing.JTextField jTfPrecio;
    // End of variables declaration//GEN-END:variables

}
